package com.exrobot.module.rbt.enums;

import com.exrobot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum RbtOrderStatusEnum implements ArrayValuable<Integer> {
    // ========== 机器人销售食物状态 ==========
    WAIT(0, "待分配"),
    SALE(1, "销售中"),
    TAKE(5, "取餐中"),
    ORDER(10, "配送中"),
    COMPLETED(20, "已完成"),
    FAIL(30, "失败"),
    EXPIRE(100, "过期/处理")
    ;

    /**
     * 类型值
     */
    private final Integer val;
    /**
     * 类型名
     */
    private final String name;

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(RbtOrderStatusEnum::getVal).toArray(Integer[]::new);

    public static RbtOrderStatusEnum validateTypeVal(Integer val) {
        for (RbtOrderStatusEnum typeEnum : RbtOrderStatusEnum.values()) {
            if (typeEnum.getVal().equals(val)) {
                return typeEnum;
            }
        }
        throw new IllegalArgumentException("非法类型： " + val);
    }

    public static String getName(Integer typeVal) {
        for (RbtOrderStatusEnum typeEnum : RbtOrderStatusEnum.values()) {
            if (typeEnum.getVal().equals(typeVal)) {
                return typeEnum.name;
            }
        }
        return "未知";
    }

    @Override
    public Integer[] array() {
        return ARRAYS;
    }
}
